home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / utils / cli.c next >
C/C++ Source or Header  |  1995-12-23  |  8KB  |  270 lines

  1. /*
  2.     Ixprefs v.2.1--ixemul.library configuration program
  3.     Copyright © 1995 Kriton Kyrimis
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include <dos/dos.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include "getopt.h"
  24.  
  25. extern void defaults(void), use(void), save(void), last_saved(void);
  26. extern int ixprefsabout(void);
  27.  
  28. extern int translateslash, membuf, watcher, redzone, blocks, cases, suppress,
  29.        amigawildcard, noflush, ignoreenv, networking;
  30.  
  31. void
  32. usage(char *prog)
  33. {
  34.   printf("Usage: %s [OPTION]...\n\nOptions:\n", prog);
  35.   printf("-a 1, --allow-amiga-wildcard\n");
  36.   printf("  accept AmigaDOS wildcard notation\n");
  37.   printf("-a 0, --no-allow-amiga-wildcard\n");
  38.   printf("  do not accept AmigaDOS wildcard notation\n");
  39.   printf("-s 1, --unix-pattern-matching-case-sensitive\n");
  40.   printf("  use case sensitive UNIX pattern matching\n");
  41.   printf("-s 0, --no-unix-pattern-matching-case-sensitive\n");
  42.   printf("  use case insensitive UNIX patter matching\n");
  43.   printf("-/ 1, --translate-slash\n");
  44.   printf("  translate /foo -> foo: and a//b -> a/b\n");
  45.   printf("-/ 0, --no-translate-slash\n");
  46.   printf("  do not translate /foo -> foo: and a//b -> a/b\n");
  47.   printf("-m N, --membuf-limit N\n");
  48.   printf("  files up to N bytes are cached in memory\n");
  49.   printf("-w 1, --watch-stack\n");
  50.   printf("  enable stack watcher\n");
  51.   printf("-w 0, --no-watch-stack\n");
  52.   printf("  disable stack watcher\n");
  53.   printf("-r N, --red-zone-size N\n");
  54.   printf("  set red zone size to N bytes\n");
  55.   printf("-b N, --fs-buf-factor N\n");
  56.   printf("  N physical blocks map into 1 logical (stdio) block\n");
  57.   printf("-i 1, --ignore-global-env\n");
  58.   printf("  ignore global environment (ENV:)\n");
  59.   printf("-i 0, --no-ignore-global-env\n");
  60.   printf("  do not ignore global environment (ENV:)\n");
  61.   printf("-v 0, --insert-disk-requester\n");
  62.   printf("  suppress the \"Insert volume in drive\" requester\n");
  63.   printf("-v 1, --no-insert-disk-requester\n");
  64.   printf("  do not suppress the \"Insert volume in drive\" requester\n");
  65.   printf("-f 0, --flush-library\n");
  66.   printf("  prevent ixemul.library from being flushed from memory\n");
  67.   printf("-f 1, --no-flush-library\n");
  68.   printf("  do not prevent ixemul.library from being flushed from memory\n");
  69.   printf("-n 0, --auto-detect\n");
  70.   printf("  set networking support to auto detect\n");
  71.   printf("-n 1, --no-networking\n");
  72.   printf("  turn off networking support\n");
  73.   printf("-n 2, --as225\n");
  74.   printf("  use AS225 networking support\n");
  75.   printf("-n 3, --amitcp\n");
  76.   printf("  use AmiTCP networking support\n");
  77.   printf("-d, --default\n");
  78.   printf("  reset settings to defaults (other options are ignored)\n");
  79.   printf("-L, --last-saved\n");
  80.   printf("  reset settings from configuration file (other options are ignored)\n");
  81.   printf("-S, --save\n");
  82.   printf("  save new configuration\n");
  83.   printf("-R, --report\n");
  84.   printf("  display new configuration\n");
  85.   printf("-V, --version\n");
  86.   printf("  display program version information (other options are ignored)\n");
  87.   printf("-h, --help\n");
  88.   printf("  display this text\n");
  89.   printf("\nUse no arguments to get the GUI\n");
  90. }
  91.  
  92. void
  93. display_config(void)
  94. {
  95.   printf((amigawildcard ? "A" : "Do not a"));
  96.   printf("ccept AmigaDOS wildcard notation,\n");
  97.   printf("Case ");
  98.   printf((cases ? "" : "in"));
  99.   printf("sensitive UNIX pattern matching,\n");
  100.   printf((translateslash ? "" : "do not "));
  101.   printf("translate /, ");
  102.   printf("membuf size = %d,\n", membuf);
  103.   printf("stack watcher is ");
  104.   printf((watcher ? "en" : "dis"));
  105.   printf("abled, red zone size = %d,\n", redzone);
  106.   printf("%d physical block", blocks);
  107.   printf(((blocks == 1) ? "" : "s"));
  108.   printf(" build");
  109.   printf(((blocks == 1) ? "s" : ""));
  110.   printf(" one logical block (for stdio),\n");
  111.   printf((ignoreenv ? "" : "do not "));
  112.   printf("ignore global environment (ENV:),\n");
  113.   printf((suppress ? "" : "do not "));
  114.   printf("suppress the \"Insert volume in drive\" requester,\n");
  115.   printf("use ");
  116.   switch (networking)
  117.   {
  118.     case 0: printf("auto-detect"); break;
  119.     case 1: printf("no"); break;
  120.     case 2: printf("AS225"); break;
  121.     case 3: printf("AmiTCP"); break;
  122.     default: printf("unknown"); break;
  123.   }
  124.   printf(" networking support,\n");
  125.   printf((noflush ? "" : "do not "));
  126.   printf("prevent ixemul.library from being flushed from memory.\n");
  127. }
  128.  
  129. int
  130. parse_cli_commands(int argc, char *argv[])
  131. {
  132.   int c, error = 0, status;
  133.   static int reset_defaults = 0, save_config = 0, help = 0, report = 0,
  134.          last = 0, version = 0;
  135.  
  136.   while (1) {
  137.     int option_index = 0;
  138.     static struct option long_options[] = {
  139.       {"insert-disk-requester", 0, &suppress, 0},        /* -v */
  140.       {"no-insert-disk-requester", 0, &suppress, 1},
  141.       {"unix-pattern-matching-case-sensitive", 0, &cases, 1},    /* -s */
  142.       {"no-unix-pattern-matching-case-sensitive", 0, &cases, 0},
  143.       {"watch-stack", 0, &watcher, 1},                /* -w */
  144.       {"no-watch-stack", 0, &watcher, 0},
  145.       {"translate-slash", 0, &translateslash, 1},        /* -/ */
  146.       {"no-translate-slash", 0, &translateslash, 0},
  147.       {"allow-amiga-wildcard", 0, &amigawildcard, 1},        /* -a */
  148.       {"no-allow-amiga-wildcard", 0, &amigawildcard, 0},
  149.       {"flush-library", 0, &noflush, 0},            /* -f */
  150.       {"no-flush-library", 0, &noflush, 1},
  151.       {"ignore-global-env", 0, &ignoreenv, 1},            /* -i */
  152.       {"no-ignore-global-env", 0, &ignoreenv, 0},
  153.       {"auto-detect", 0, &networking, 0},
  154.       {"no-networking", 0, &networking, 1},
  155.       {"as225", 0, &networking, 2},
  156.       {"amitcp", 0, &networking, 3},
  157.       {"membuf-limit", 1, 0, 'm'},                /* -m */
  158.       {"red-zone-size", 1, 0, 'r'},                /* -r */
  159.       {"fs-buf-factor", 1, 0, 'b'},                /* -b */
  160.       {"default", 0, &reset_defaults, 1},            /* -d */
  161.       {"save", 0, &save_config, 1},                /* -S */
  162.       {"report", 0, &report, 1},                /* -R */
  163.       {"last-saved", 0, &last, 1},                /* -L */
  164.       {"version", 0, &version, 1},                /* -V */
  165.       {"help", 0, &help, 1},                    /* -h */
  166.       {0, 0, 0, 0}
  167.     };
  168.     c = getopt_long (argc, argv, "v:s:x:w:a:/:f:i:m:n:r:b:dShRLV",
  169.                  long_options, &option_index);
  170.     if (c == EOF) {
  171.       break;
  172.     }
  173.     switch (c) {
  174.       case 0:
  175.     break;
  176.       case 'v':
  177.     suppress = (atoi(optarg) ? 0 : 1);
  178.     break;
  179.       case 's':
  180.     cases = (atoi(optarg) ? 1 : 0);
  181.     break;
  182.       case 'w':
  183.     watcher = (atoi(optarg) ? 1 : 0);
  184.     break;
  185.       case 'a':
  186.     amigawildcard = (atoi(optarg) ? 1 : 0);
  187.     break;
  188.       case '/':
  189.     translateslash = (atoi(optarg) ? 1 : 0);
  190.     break;
  191.       case 'f':
  192.         noflush = (atoi(optarg) ? 0 : 1);
  193.     break;
  194.       case 'i':
  195.         ignoreenv = atoi(optarg);
  196.     break;
  197.       case 'm':
  198.     membuf = atoi(optarg);
  199.     break;
  200.       case 'n':
  201.     networking = atoi(optarg);
  202.     break;
  203.       case 'r':
  204.     redzone = atoi(optarg);
  205.     break;
  206.       case 'b':
  207.     blocks = atoi(optarg);
  208.     break;
  209.       case 'd':
  210.     reset_defaults = 1;
  211.     break;
  212.       case 'S':
  213.     save_config = 1;
  214.     break;
  215.       case 'h':
  216.         help = 1;
  217.     break;
  218.       case 'R':
  219.         report = 1;
  220.     break;
  221.       case 'L':
  222.         last = 1;
  223.     break;
  224.       case 'V':
  225.         version = 1;
  226.     break;
  227.       default:
  228.     error = 1;
  229.     break;
  230.     }
  231.   }
  232.   if (optind < argc) {
  233.     error = 1;
  234.   }
  235.   if (error) {
  236.     fprintf(stderr, "\n");
  237.     usage(argv[0]);
  238.     status = RETURN_FAIL;
  239.   }else{
  240.     status = RETURN_OK;
  241.     if (version) {
  242.       (void)ixprefsabout();
  243.     }else{
  244.       if (help) {
  245.     usage(argv[0]);
  246.       }else{
  247.     if (last) {
  248.       if (reset_defaults) {
  249.         fprintf(stderr,
  250.   "--last-saved and --default specified together.  --default ignored.\n");
  251.       }
  252.       last_saved();
  253.     }
  254.     if (reset_defaults) {
  255.       defaults();
  256.     }
  257.     if (save_config) {
  258.       save();
  259.     }else{
  260.       use();
  261.     }
  262.     if (report) {
  263.       display_config();
  264.     }
  265.       }
  266.     }
  267.   }
  268.   return status;
  269. }
  270.